package com.company.project.web;
import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.model.PeriodicalsCategory;
import com.company.project.service.PeriodicalsCategoryService;
import com.company.project.util.PageUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created by CodeGenerator on 2018/10/10.
*/
@RestController
@RequestMapping("/periodicals/category")
public class PeriodicalsCategoryController {
    @Resource
    private PeriodicalsCategoryService periodicalsCategoryService;

    //后台查询
    @GetMapping("/admin/list/{index}")
    public PageUtil<Map<Object,Object>> adminPeriodicalsCategoryList(@PathVariable("index") Integer index){
        return periodicalsCategoryService.adminSelectPc(index);
    }

    //后台添加期刊获取期刊专业
    @GetMapping("/admin/periodicalslist")
    @ResponseBody
    public List<PeriodicalsCategory> adminPPeriodicalsCategoryListPeriodicalsCategory(){
       return periodicalsCategoryService.adminGetPcP();
    }

    /**
     * 后台修改期刊专业
     * @param periodicalsCategory
     * @return
     */
    @PostMapping("/adminUpPc")
    @ResponseBody
    public Boolean adminUpPc(@RequestBody PeriodicalsCategory periodicalsCategory){
      return   periodicalsCategoryService.adminUpPc(periodicalsCategory);
    }

    /**
     * 后台添加期刊专业
     * @param periodicalsCategory
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public Boolean adminAddPc(@RequestBody PeriodicalsCategory periodicalsCategory) {
      return   periodicalsCategoryService.adminAddPc(periodicalsCategory);
    }

    /**
     * 查询所有一级专业
     * @return
     */
    @GetMapping("/stair")
    @ResponseBody
    public Result stair(){
        List<PeriodicalsCategory> stair = periodicalsCategoryService.stair();
        return ResultGenerator.genSuccessResult(stair);
    }
    /**
     * 后台删除期刊专业
     * @param periodicalsCategory
     * @return
     */
    @PostMapping("/delete")
    @ResponseBody
    public Boolean adminDelPc(@RequestBody PeriodicalsCategory periodicalsCategory) {
        return periodicalsCategoryService.adminDelPc(periodicalsCategory);

    }

    @PostMapping("/update")
    public Result update(PeriodicalsCategory periodicalsCategory) {
        periodicalsCategoryService.update(periodicalsCategory);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        PeriodicalsCategory periodicalsCategory = periodicalsCategoryService.findById(id);
        return ResultGenerator.genSuccessResult(periodicalsCategory);
    }

    //期刊专业，根据param查询
    @GetMapping("/list/{parent}")
    @ResponseBody
    public Result list(@PathVariable("parent") Integer parent) {
        List<PeriodicalsCategory> periodicalsCategoryByParent = periodicalsCategoryService.getPeriodicalsCategoryByParent(parent);
        return ResultGenerator.genSuccessResult(periodicalsCategoryService.getPeriodicalsCategoryByParent(parent));
    }
}
